package leetcode_core.leetcode_2;

import org.omg.CORBA.PRIVATE_MEMBER;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class CombinationSum2 {
    private List<List<Integer>> ans = new ArrayList<>();

    public List<List<Integer>> combinationSum2(int[] candidates, int target) {
        Arrays.sort(candidates);
        backtrack(candidates,target,0,new LinkedList<>());
        return null;
    }

    private void backtrack(int[] nums,int target,int start,LinkedList<Integer> track){
        if(target == 0){
            ans.add(new ArrayList<>(track));
            return;
        }
        if(target < 0){
            return;
        }
        for(int i = start;i<nums.length;i++){
            //避免重复
            if(i>start && nums[i-1] == nums[i]){
                continue;
            }
            //做选择
            track.add(nums[i] );
            //递归回溯
            backtrack(nums,target-nums[i],i+1,track);
            //撤销选择
            track.removeLast();
        }
    }


}
